#pragma once
#include "../../include/types.h"
#include "../proc/spinlock.h"
#include "../../include/riscv.h"
#include "buf.h"
#include "sleeplock.h"

struct bcache {
  spinlock lock;
  struct buf buf[NBUF];

  // Linked list of all buffers, through prev/next.
  // Sorted by how recently the buffer was used.
  // head.next is most recent, head.prev is least.
  struct buf head;
};

extern struct bcache bcache;

void
binit(void);

struct buf*
bget(uint32 dev, uint32 blockno);

void
bwrite(struct buf *b);

void
brelse(struct buf *b);

void
bpin(struct buf *b);

struct buf*
bread(uint32 dev, uint32 blockno);